//
//  ProtectionViewController.m
//  SelfDriving
//
//  Created by apple on 16/3/10.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ProtectionViewController.h"
#import "BusinessService+User.h"
@interface ProtectionViewController ()<UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UISwitch *swch;

@end

@implementation ProtectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   

}
-(void)viewWillAppear:(BOOL)animated{
    if ([AppDelegate shareDelegate].user.safe_phone.length !=0) {
        [_swch setOn:YES];
    }else{
        [_swch setOn:NO];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma  mark 开启或关闭
- (IBAction)kaiqiAction:(UISwitch *)sender {
    if(sender.on){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"开启登录保护" message:@"你需要验证当前设备" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        alert.tag = 1;
        [alert show];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"关闭登录保护" message:@"你确定要关闭登陆保护？" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        alert.tag = 2;
        [alert show];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag ==1) {//开启
        if (buttonIndex == 0) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"PhoneverificationVC"];
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }else{
            [_swch setOn:!_swch.on];
        }
    }else{//关闭
        if (buttonIndex == 0) {
             [[BusinessService shareInstance]close_safe_login:[[NSMutableDictionary alloc]init] success:^(id result) {
                 [_swch setOn:NO];
             } failure:^(id result) {
                 [_swch setOn:!_swch.on];
                 [SVProgressHUD showErrorWithStatus:result];
             }];
        }else{
            [_swch setOn:!_swch.on];
        }
    }
}
#pragma  mark 返回
- (IBAction)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
